package com.zgjl.api.util;

/**
 * 工具类：为第三方生成接入凭证
 */
public class KeyManager {

    // 雪花算法生成器（生成纯数字 appId）
    private static final SnowflakeIdGenerator snowflake = new SnowflakeIdGenerator(1, 1);

    /**
     * 创建一组凭证
     */
    public static ClientCredential createCredential() {
        long appId = snowflake.nextId();
        String appSecret = KeyGeneratorTool.generateJWTSecretKey();
        String sm4Key = KeyGeneratorTool.generateSM4Key();
        return new ClientCredential(appId, appSecret, sm4Key);
    }
}

/**
 * 封装一组第三方凭证
 */
class ClientCredential {
    private final long appId;
    private final String appSecret;
    private final String sm4Key;

    public ClientCredential(long appId, String appSecret, String sm4Key) {
        this.appId = appId;
        this.appSecret = appSecret;
        this.sm4Key = sm4Key;
    }

    public long getAppId() {
        return appId;
    }

    public String getAppSecret() {
        return appSecret;
    }

    public String getSm4Key() {
        return sm4Key;
    }
}
